package com.crm.controller.after_sale;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crm.pojo.AftetSaleServer;
import com.crm.service.after_sale.AftetSaleServerService;
import com.crm.vo.Result;

@Controller
public class AftetSaleServerController {

	@Autowired
	private AftetSaleServerService aftetSaleServerService;
	
	/**
	 * 售后服务页面
	 * @return
	 */
	@GetMapping("/after-sale-server")
	public String afterSaleServer() {
		return "after-sale/after-sale-server";
	}
	
	/**
	 * 添加售后服务页面
	 * @return
	 */
	@GetMapping("/to-add-after-sale-server-from")
	public String toAddAfterSaleServer() {
		return "after-sale/add-after-sale-server-form";
	}
	
	/**
	 * 编辑售后服务页面
	 * @return
	 */
	@GetMapping("/to-edit-after-sale-server-from")
	public String toEditAfterSaleServer() {
		return "after-sale/edit-after-sale-server-form";
	}
	
	/**
	 * 售后服务视图
	 * @return
	 */
	@GetMapping("/to-view-after-sale-server-from")
	public String toViewAfterSaleServer() {
		return "after-sale/view-after-sale-server-form";
	}
	
	
	/**
	 * 分页查询售后服务
	 * @param page
	 * @param rows
	 * @return
	 */
	@PostMapping("/find-after-sale-server-by-page")
	@ResponseBody
	public Map findAllNotDelBypage(int page, int rows){
		Long total = aftetSaleServerService.countAllNotDelBypage();
		List<AftetSaleServer> aftetSaleServers = aftetSaleServerService.findAllNotDelBypage(page, rows);
		Map map = new HashMap<>();
		map.put("total", total);
		map.put("rows", aftetSaleServers);
		return map;
	}
	
	/**
	 * 添加售后服务
	 * @param aftetSaleServer
	 * @return
	 */
	@PostMapping("/add-after-sale-server")
	@ResponseBody
	public Result addAfterSaleServer(AftetSaleServer aftetSaleServer) {
		return aftetSaleServerService.addAftetSaleServe(aftetSaleServer);
	}
	
	/**
	 * 删除售后服务
	 * @param serverId
	 * @return
	 */
	@PostMapping("/del-after-sale-server")
	@ResponseBody
	public Result delAftetSaleServe(Long serverId) {
		return aftetSaleServerService.delAftetSaleServe(serverId);
	}
	
	/**
	 * 编辑售后服务
	 * @param aftetSaleServer
	 * @return
	 */
	@PostMapping("/edit-after-sale-server")
	@ResponseBody
	public Result editAftetSaleServe(AftetSaleServer aftetSaleServer) {
		return aftetSaleServerService.editAftetSaleServe(aftetSaleServer);
	}
	
	/**
	 * 根据服务编号查询售后服务
	 * @param serverId
	 * @param page
	 * @param rows
	 * @return
	 */
	@PostMapping("/find-after-sale-server-by-serverId")
	@ResponseBody
	public Map findOneNotDel(Long serverId,int page, int rows){
		List<AftetSaleServer> aftetSaleServers = aftetSaleServerService.findOneNotDel(serverId, page, rows);
		Map map = new HashMap<>();
		map.put("total", 1);
		map.put("rows", aftetSaleServers);
		return map;
	}
	
	/**
	 * 根据服务主题查询客户服务
	 * @param theme
	 * @param page
	 * @param rows
	 * @return
	 */
	@PostMapping("/find-after-sale-server-by-theme")
	@ResponseBody
	public Map findByTheme(String theme, int page, int rows){
		Long total = aftetSaleServerService.countByTheme(theme);
		List<AftetSaleServer> aftetSaleServers = aftetSaleServerService.findByTheme(theme, page, rows);
		Map map = new HashMap<>();
		map.put("total", total);
		map.put("rows", aftetSaleServers);
		return map;
	}
}
